package fr.lelouet.ga.reducers.competitors;

import fr.lelouet.ga.reducers.Competitor;
import fr.lelouet.ga.reducers.Evaluator;

/**
 * Competitor that evaluates elements passed, and the loser is the one with the
 * lowest value
 * 
 * @author admin
 */
public class EvaluatingCompetitor<T> implements Competitor<T> {

    protected Evaluator<T> evaluator;

    public EvaluatingCompetitor(Evaluator<T> evaluator) {
	this.evaluator = evaluator;
    }

    @Override
    public T loser(T a, T b) {
	if (evaluator.eval(a) < evaluator.eval(b)) {
	    return a;
	} else {
	    return b;
	}
    }

}
